n=int(input())
if x>999 and x<10000:
    t=0
    for i1 in range(0,4):
        for i2 in range(i1+1,5):
            m=x%10**i2//10**i1
            if y!=0 and y!=1:
                for i in range(2,y):
                    if y%i==0:
                        break
                else:
                    if m>t:
                        t=m
    print(t)
    
